<template>
	<view>
		<view class="search">
			<view class="search-r">
				<u-search :focus="focus" @custom="keyword = '';search()" action-text="取消" :show-action="keyword" :action-style="{color:'#dd592f','margin-left':'0','margin-right':'20rpx'}" bg-color="#fff" @search="search" placeholder="搜索你需要的" v-model="keyword"></u-search>
			</view>
		</view>
		<view class="list">
			<view class="item u-flex" v-for="(item,index) in list" :key="item.id" @click="jump(`/pages/news/article?id=${item.id}`)">
				<image :src="item.cover"></image>
				<view class="info u-flex-1">
					<view class="title u-line-1">{{item.title}}</view>
					<view class="text u-line-2">{{item.des}}</view>
				</view>
			</view>
		</view>
		
		<!-- 底部安全区适配 -->
		<view class="safe-area-inset-bottom"></view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				keyword:'',
				cate:'',
				page:1,
				status:'loading',
				list:[],
				focus:!1
			}
		},
		methods: {
			getList(){
				this.status = 'loading'
				this.$u.api.article({
					page:this.page,
					limit:15,
					keyword:this.keyword,
					cate:this.cate
				}).then(res=>{
					this.list = this.page == 1 ? res : this.list.concat(res)
					this.status = res.length  === 15 ? 'loadmore' : 'nomore'
					uni.stopPullDownRefresh()
				})
			},
			search(){
				this.page = 1
				this.getList()
			}
		},
		onLoad(o) {
			this.cate = o.cate
			this.focus = o.focus == 1 ? !0 : !1
			this.getList()
		},
		onReady() {
			const title = ['','情感维护','情感表达','情感挽回']
			this.$app.setTitle(title[Number(this.cate)])
		},
		onReachBottom() {
			if(this.status == 'loadmore'){
				this.page ++
				this.getList()
			}
		},
		onPullDownRefresh() {
			this.page = 1
			this.getList()
		}
	}
</script>

<style lang="scss">
	page{background-color: #f1f1f1;}
	.search{padding: 20rpx 40rpx;background-color: #f1f1f1;position: sticky;top: 0;left: 0;z-index: 5;
		.search-r{border-radius: 100rpx;box-shadow: 6rpx 6rpx 16rpx rgba($color: #000000, $alpha: .1);background-color: #fff;}
	}
	.list{
		padding: 0 40rpx;
		.item{
			margin-top: 20rpx;background-color: #fff;border-radius: 20rpx;padding: 30rpx 20rpx;
			&:first-child{margin-top: 0;}
			image{flex-shrink: 0;width: 160rpx;height: 160rpx;display: block;border-radius: 10rpx;}
			.info{margin-left: 20rpx;overflow: hidden;word-break: break-word;
				.title{font-size: 32rpx;font-weight: bold;}
				.text{font-size: 26rpx;margin-top: 20rpx;line-height: 35rpx;height: 70rpx;}
			}
		}
	}
</style>
